﻿// 转换为数字    
function intprase(v) {
    v = parseInt(v);
    return isNaN(v) ? 0 : v;
}

// 获取元素信息    
function getInfo(e) {
    var l = 0;
    var t = 0;
    var w = intprase(e.style.width);
    var h = intprase(e.style.height);
    var wb = e.offsetWidth;
    var hb = e.offsetHeight;
    while (e.offsetParent) {
        l += e.offsetLeft + (e.currentStyle ? intprase(e.currentStyle.borderLeftWidth) : 0);
        t += e.offsetTop + (e.currentStyle ? intprase(e.currentStyle.borderTopWidth) : 0);
        e = e.offsetParent;
    }
    l += e.offsetLeft + (e.currentStyle ? intprase(e.currentStyle.borderLeftWidth) : 0);
    t += e.offsetTop + (e.currentStyle ? intprase(e.currentStyle.borderTopWidth) : 0);
    return {
        x: l,
        y: t,
        w: w,
        h: h,
        wb: wb,
        hb: hb
    };
}

// 获取滚动条信息    
function getScroll() {
    var t, l, w, h;
    if (document.documentElement && document.documentElement.scrollTop) {
        t = document.documentElement.scrollTop;
        l = document.documentElement.scrollLeft;
        w = document.documentElement.scrollWidth;
        h = document.documentElement.scrollHeight;
    }
    else
        if (document.body) {
        t = document.body.scrollTop;
        l = document.body.scrollLeft;
        w = document.body.scrollWidth;
        h = document.body.scrollHeight;
    }
    return {
        t: t,
        l: l,
        w: w,
        h: h
    };
}

// 锚点(Anchor)间平滑跳转    
function glide(el, duration) {
    if (typeof el != 'object') {
        el = document.getElementById(el);
    }
    if (!el)
        return;
    var z = this;
    z.el = el;
    z.p = getInfo(el);
    z.s = getScroll();
    z.clear = function() {
        window.clearInterval(z.timer);
        z.timer = null
    };
    z.t = (new Date).getTime();
    z.step = function() {
        var t = (new Date).getTime();
        var p = (t - z.t) / duration;
        if (t >= duration + z.t) {
            z.clear();
            window.setTimeout(function() {
                z.scroll(z.p.y, z.p.x)
            }, 13);
        }
        else {
            st = ((-Math.cos(p * Math.PI) / 2) + 0.5) * (z.p.y - z.s.t) + z.s.t;
            sl = ((-Math.cos(p * Math.PI) / 2) + 0.5) * (z.p.x - z.s.l) + z.s.l;
            z.scroll(st, sl);
        }
    };
    z.scroll = function(t, l) {
        window.scrollTo(l, t)
    };
    z.timer = window.setInterval(function() {
        z.step();
    }, 13);
}


//div 悬浮
function drag(o, s) {

    if (typeof o == "string") o = document.getElementById(o);

    o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;

    o.orig_y = parseInt(o.style.top) - document.body.scrollTop;

    o.orig_index = o.style.zIndex;

    //author: www.longbill.cn 

    o.onmousedown = function(a) {

        this.style.cursor = "move";

        this.style.zIndex = 10000;

        var d = document;

        if (!a) a = window.event;

//        var x = a.clientX + d.body.scrollLeft - o.offsetLeft;

//        var y = a.clientY + d.body.scrollTop - o.offsetTop;


        var x = a.clientX + d.body.scrollLeft ;

        var y = a.clientY + d.body.scrollTop ;

        d.ondragstart = "return false;"

        d.onselectstart = "return false;"

        d.onselect = "document.selection.empty();"



        if (o.setCapture)

            o.setCapture();

        else if (window.captureEvents)

            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);



        d.onmousemove = function(a) {

            if (!a) a = window.event;

            o.style.left = a.clientX + document.body.scrollLeft - x;

            o.style.top = a.clientY + document.body.scrollTop - y;

            o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;

            o.orig_y = parseInt(o.style.top) - document.body.scrollTop;

        }



        d.onmouseup = function() {

            if (o.releaseCapture)

                o.releaseCapture();

            else if (window.captureEvents)

                window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);

            d.onmousemove = null;

            d.onmouseup = null;

            d.ondragstart = null;

            d.onselectstart = null;

            d.onselect = null;

            o.style.cursor = "normal";

            o.style.zIndex = o.orig_index;

        }

    }



    if (s) {

        var orig_scroll = window.onscroll ? window.onscroll : function() { };

        window.onscroll = function() {

            orig_scroll();

            o.style.left = o.orig_x + document.body.scrollLeft;

            o.style.top = o.orig_y + document.body.scrollTop;

        }

    }

}




function OpenJobList() {
//    $dialog("../JobManagement/JobList.aspx", { width: 790, height: 560 ,x: 215, y: 0 });
}

//2008-10-10
function CheckDateFormat(objThis) {
    var strRex = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
    if (objThis.value.length > 0) {
        if (strRex.test(objThis.value)) {
        }
        else {
            $alert("Please input in a correct date format.", function(result) {
                objThis.focus();
            });
        }
    }
}



//***********默认设置定义.*********************   
tPopWait = 50; //停留tWait豪秒后显示提示。   
tPopShow = 10000; //显示tShow豪秒后关闭提示   
showPopStep = 100;
popOpacity = 99;

//***************内部变量定义*****************   
sPop = null;
curShow = null;
tFadeOut = null;
tFadeIn = null;
tFadeWaiting = null;

document.write("<style   type='text/css'id='defaultPopStyle'>");
document.write(".cPopText   {background-color:#FFFFE1;color:#000000;   border:2px solid #E0F0FF;font-size:9pt; width:400px;   padding:10px;     filter:   Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div   id='dypopLayer'   style='position:absolute;z-index:1000;display:none;'   class='cPopText'></div>");


function showPopupText() {

    var o = event.srcElement;
    if (o != null) {
        MouseX = event.x;
        MouseY = event.y;
        if (o.alt != null && o.alt != "") { o.dypop = o.alt; o.alt = "" };
        if (o.title != null && o.title != "") { o.dypop = o.title; o.title = "" };
        if (o.dypop != sPop) {
            sPop = o.dypop;
            clearTimeout(curShow);
            clearTimeout(tFadeOut);
            clearTimeout(tFadeIn);
            clearTimeout(tFadeWaiting);
            if (sPop == null || sPop == "") {
                dypopLayer.style.display = "none";
                dypopLayer.innerHTML = "";
                //            dypopLayer.style.filter = "Alpha()";
                //            dypopLayer.filters.Alpha.opacity = 0;
            }
            else {

                if (o.dyclass != null) popStyle = o.dyclass
                else popStyle = "cPopText";
                curShow = setTimeout("showIt()", tPopWait);
            }
        }
    }
}

function showIt() {
    dypopLayer.style.display = "block";
    dypopLayer.className = popStyle;
    dypopLayer.innerHTML = sPop;
    popWidth = dypopLayer.clientWidth;
    popHeight = dypopLayer.clientHeight;
    if (MouseX + 12 + popWidth > document.body.clientWidth) popLeftAdjust = -popWidth - 24
    else popLeftAdjust = 0;
    if (MouseY + 12 + popHeight > document.body.clientHeight) popTopAdjust = -popHeight - 24
    else popTopAdjust = 0;
    dypopLayer.style.left = MouseX + 12 + document.body.scrollLeft + popLeftAdjust;
    dypopLayer.style.top = MouseY + 12 + document.body.scrollTop + popTopAdjust;
//    dypopLayer.style.filter = "Alpha(Opacity=0)";
    fadeOut();
}

function fadeOut() {
    if (dypopLayer.filters.Alpha.opacity < popOpacity) {
        dypopLayer.filters.Alpha.opacity += showPopStep;
        tFadeOut = setTimeout("fadeOut()", 1);
    }
    else {
        dypopLayer.filters.Alpha.opacity = popOpacity;
        tFadeWaiting = setTimeout("fadeIn()", tPopShow);
    }
}

function fadeIn() {
    if (dypopLayer.filters.Alpha.opacity > 0) {
        dypopLayer.filters.Alpha.opacity -= 1;
        tFadeIn = setTimeout("fadeIn()", 1);
        dypopLayer.style.display = "none";
    }
}
document.onmouseover = showPopupText;




